package c.x.jy.wexin.controller;

import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.entity.BirthEntity;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.service.service.BirthService;
import c.x.jy.service.service.MemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 会员八字表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-25 11:30:56
 */
@RestController
@RequestMapping("wechat/birth")
public class BirthController  {
    @Autowired
    private BirthService birthService;
    @Autowired
    MemberService memberService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @Login
    public R list(@RequestParam Map<String, Object> params){
        MemberEntity memberEntity = memberService.getCurrUser();
        Long memberId = memberEntity.getId();
        params.put("memberId",memberId);

        PageUtils page = birthService.queryPage(params);

        return R.put(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public R info(@PathVariable("id") Long id){
		BirthEntity birth = birthService.getById(id);

        return R.put(birth);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @Login
    public R save(@RequestBody BirthEntity birth){

        MemberEntity memberEntity = memberService.getCurrUser();
        birth.setMemberId(memberEntity.getId());
        birthService.save(birth);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("member:birth:update")
    public R update(@RequestBody BirthEntity birth){
		birthService.updateById(birth);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @Login
    public R delete(@PathVariable("id") Long id){
		birthService.removeByIds(Arrays.asList(id));

        return R.ok();
    }

}

